<?php
header('Content-type:text/html;charset=utf-8');
require 'public_function.php';
$link=dbInit();

$order=$_GET['order'];
$sort=$_GET['sort'];
$fields=array('e_dept','date_of_entry');
$sql_order='';
$order=isset($_GET['order']) ? $_GET['order']:'';
$sort=isset($GET['sort']) ? $_GET['sort']:'';
if (in_array($order,$fields)){
    if ($sort=='desc'){
        $sql_order="order by $order desc";
        $sort='asc';
    }else{
        $sql_order="order by $order asc";
        $sort='desc';
    }
}

$where='';
if (isset($_GET['keyword'])){
    $keyword=$_GET['keyword'];
    $keyword=mysqli_real_escape_string($link,$keyword);
    $where="where e_name like '%$keyword%'";
}

$sql='select* from `emp_info` ';
$emp_info=fetchAll($link,$sql);

$sql="select*from `emp_info` $sql_order $where ";
$result=mysqli_query($link,$sql);


define('APP','itcast');
require './list_html.php';